import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wq3stone
 */
public class SumServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int num1 = 0;
        int num2 = 0;
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        try {
            num1 = Integer.parseInt(req.getParameter("num1"));
            num2 = Integer.parseInt(req.getParameter("num2"));
            resp.getWriter().print(num1+num2);
        } catch (NumberFormatException e) {
            resp.getWriter().print("请不要输入数字以外的字符");
        }
    }
}
